12. 3 or more stocks (optional)

Extending to 3 stocks (optional)

Now let’s extend this concept to three stocks. If we analyze three stock series with the Johansen, we can determine whether all three stocks together have a cointegrated relationship, and that a linear combination of all three form a stationary series. Note that for the purpose of cointegration trading we use the original price series, and do not convert them to log returns. The Johansen test also lets us decide whether only two series are needed to form a stationary series, but for now, let’s assume that we find a trio of stocks that are cointegrated.

The Johansen gives us three coefficients, one for each stock series. We take the linear combination to get a spread.

w_1 \times stock_1 + w_2 \times stock_2 + w_3 \times stock_3 = spread

We get the historical average of the spread. Then we check if the spread deviates significantly from that average. For example, let’s say the spread increases significantly. So we check whether each of the three individual series moved up or down significantly to result in the change in spread. We short the series that are relatively high, and long the series that are relatively low. To determine how much to long or short, we again use the weights that are given by the Johansen test (w_1, w_2, w_3) .

For example, let’s say the spread has gotten larger. Let’s also pretend that w_1 is 0.5, w_2 is 0.3, and w_3 is -0.1. Notice that the weights do not need to sum to 1. We’ll long or short the number of shares for each stock in these proportions. So for instance, if we traded 5 shares of stock_1 , we’ll trade 3 shares of stock_2 , and one share of stock_3 .

If we notice that stock_1 is higher than normal, stock_2 is lower than normal, and stock_3 is lower than normal, then let’s see whether we long or short a stock, and by how much.

Since stock_1 is higher than usual (relative to the others), we short 5 shares of stock_1 because we expect it should revert by decreasing relative to the others.

Since stock_2 is lower than normal, we long it by 3 shares, because we expect it to revert by increasing relative to the others.

Since stock_3 is lower than normal, so we also long it by 1 share but notice that w_3 is a negative number (-0.1). Whenever we see a negative weight, it means we change a buy to a sell, or change a sell to a buy. So we long a -1 shares, which is actually shorting 1 share.